﻿///////////////////////////////////////////////////////////////
// This is generated code. 
//////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: 2.6
// Code is generated on: Tuesday, April 08, 2014 5:21:30 PM
// Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20
// Templates vendor: Solutions Design.
// Templates version: 
//////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using TuanHuy.DAL.EntityClasses;
using TuanHuy.DAL.HelperClasses;
using TuanHuy.DAL.RelationClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace TuanHuy.DAL.FactoryClasses
{
	
	// __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
	// __LLBLGENPRO_USER_CODE_REGION_END
	
	/// <summary>general base class for the generated factories</summary>
	[Serializable]
	public partial class EntityFactoryBase2 : EntityFactoryCore2
	{
		private string _entityName;
		private TuanHuy.DAL.EntityType _typeOfEntity;
		
		/// <summary>CTor</summary>
		/// <param name="entityName">Name of the entity.</param>
		/// <param name="typeOfEntity">The type of entity.</param>
		public EntityFactoryBase2(string entityName, TuanHuy.DAL.EntityType typeOfEntity)
		{
			_entityName = entityName;
			_typeOfEntity = typeOfEntity;
		}
		
		/// <summary>Creates, using the generated EntityFieldsFactory, the IEntityFields2 object for the entity to create.</summary>
		/// <returns>Empty IEntityFields2 object.</returns>
		public override IEntityFields2 CreateFields()
		{
			return EntityFieldsFactory.CreateEntityFieldsObject(_typeOfEntity);
		}
		
		/// <summary>Creates a new entity instance using the GeneralEntityFactory in the generated code, using the passed in entitytype value</summary>
		/// <param name="entityTypeValue">The entity type value of the entity to create an instance for.</param>
		/// <returns>new IEntity instance</returns>
		public override IEntity2 CreateEntityFromEntityTypeValue(int entityTypeValue)
		{
			return GeneralEntityFactory.Create((TuanHuy.DAL.EntityType)entityTypeValue);
		}

		/// <summary>Creates the relations collection to the entity to join all targets so this entity can be fetched. </summary>
		/// <param name="objectAlias">The object alias to use for the elements in the relations.</param>
		/// <returns>null if the entity isn't in a hierarchy of type TargetPerEntity, otherwise the relations collection needed to join all targets together to fetch all subtypes of this entity and this entity itself</returns>
		public override IRelationCollection CreateHierarchyRelations(string objectAlias) 
		{
			return InheritanceInfoProviderSingleton.GetInstance().GetHierarchyRelations(_entityName, objectAlias);
		}

		/// <summary>This method retrieves, using the InheritanceInfoprovider, the factory for the entity represented by the values passed in.</summary>
		/// <param name="fieldValues">Field values read from the db, to determine which factory to return, based on the field values passed in.</param>
		/// <param name="entityFieldStartIndexesPerEntity">indexes into values where per entity type their own fields start.</param>
		/// <returns>the factory for the entity which is represented by the values passed in.</returns>
		public override IEntityFactory2 GetEntityFactory(object[] fieldValues, Dictionary<string, int> entityFieldStartIndexesPerEntity) 
		{
			IEntityFactory2 toReturn = (IEntityFactory2)InheritanceInfoProviderSingleton.GetInstance().GetEntityFactory(_entityName, fieldValues, entityFieldStartIndexesPerEntity);
			if(toReturn == null)
			{
				toReturn = this;
			}
			return toReturn;
		}
		
		/// <summary>Gets a predicateexpression which filters on the entity with type belonging to this factory.</summary>
		/// <param name="negate">Flag to produce a NOT filter, (true), or a normal filter (false). </param>
		/// <param name="objectAlias">The object alias to use for the predicate(s).</param>
		/// <returns>ready to use predicateexpression, or an empty predicate expression if the belonging entity isn't a hierarchical type.</returns>
		public override IPredicateExpression GetEntityTypeFilter(bool negate, string objectAlias) 
		{
			return InheritanceInfoProviderSingleton.GetInstance().GetEntityTypeFilter(this.ForEntityName, objectAlias, negate);
		}
				
		/// <summary>returns the name of the entity this factory is for, e.g. "EmployeeEntity"</summary>
		public override string ForEntityName 
		{ 
			get { return _entityName; }
		}
	}
	
	/// <summary>Factory to create new, empty AspnetApplicationsEntity objects.</summary>
	[Serializable]
	public partial class AspnetApplicationsEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public AspnetApplicationsEntityFactory() : base("AspnetApplicationsEntity", TuanHuy.DAL.EntityType.AspnetApplicationsEntity) { }

		/// <summary>Creates a new, empty AspnetApplicationsEntity object.</summary>
		/// <returns>A new, empty AspnetApplicationsEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new AspnetApplicationsEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewAspnetApplications
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new AspnetApplicationsEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new AspnetApplicationsEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewAspnetApplicationsUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<AspnetApplicationsEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty AspnetMembershipEntity objects.</summary>
	[Serializable]
	public partial class AspnetMembershipEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public AspnetMembershipEntityFactory() : base("AspnetMembershipEntity", TuanHuy.DAL.EntityType.AspnetMembershipEntity) { }

		/// <summary>Creates a new, empty AspnetMembershipEntity object.</summary>
		/// <returns>A new, empty AspnetMembershipEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new AspnetMembershipEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewAspnetMembership
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new AspnetMembershipEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new AspnetMembershipEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewAspnetMembershipUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<AspnetMembershipEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty AspnetSchemaVersionsEntity objects.</summary>
	[Serializable]
	public partial class AspnetSchemaVersionsEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public AspnetSchemaVersionsEntityFactory() : base("AspnetSchemaVersionsEntity", TuanHuy.DAL.EntityType.AspnetSchemaVersionsEntity) { }

		/// <summary>Creates a new, empty AspnetSchemaVersionsEntity object.</summary>
		/// <returns>A new, empty AspnetSchemaVersionsEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new AspnetSchemaVersionsEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewAspnetSchemaVersions
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new AspnetSchemaVersionsEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new AspnetSchemaVersionsEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewAspnetSchemaVersionsUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<AspnetSchemaVersionsEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty AspnetUsersEntity objects.</summary>
	[Serializable]
	public partial class AspnetUsersEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public AspnetUsersEntityFactory() : base("AspnetUsersEntity", TuanHuy.DAL.EntityType.AspnetUsersEntity) { }

		/// <summary>Creates a new, empty AspnetUsersEntity object.</summary>
		/// <returns>A new, empty AspnetUsersEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new AspnetUsersEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewAspnetUsers
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new AspnetUsersEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new AspnetUsersEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewAspnetUsersUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<AspnetUsersEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty CategoryEntity objects.</summary>
	[Serializable]
	public partial class CategoryEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public CategoryEntityFactory() : base("CategoryEntity", TuanHuy.DAL.EntityType.CategoryEntity) { }

		/// <summary>Creates a new, empty CategoryEntity object.</summary>
		/// <returns>A new, empty CategoryEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new CategoryEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewCategory
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new CategoryEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new CategoryEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewCategoryUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<CategoryEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty GalleriesEntity objects.</summary>
	[Serializable]
	public partial class GalleriesEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public GalleriesEntityFactory() : base("GalleriesEntity", TuanHuy.DAL.EntityType.GalleriesEntity) { }

		/// <summary>Creates a new, empty GalleriesEntity object.</summary>
		/// <returns>A new, empty GalleriesEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new GalleriesEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewGalleries
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new GalleriesEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new GalleriesEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewGalleriesUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<GalleriesEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty GalleryCategoryEntity objects.</summary>
	[Serializable]
	public partial class GalleryCategoryEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public GalleryCategoryEntityFactory() : base("GalleryCategoryEntity", TuanHuy.DAL.EntityType.GalleryCategoryEntity) { }

		/// <summary>Creates a new, empty GalleryCategoryEntity object.</summary>
		/// <returns>A new, empty GalleryCategoryEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new GalleryCategoryEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewGalleryCategory
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new GalleryCategoryEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new GalleryCategoryEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewGalleryCategoryUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<GalleryCategoryEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty LanguageEntity objects.</summary>
	[Serializable]
	public partial class LanguageEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public LanguageEntityFactory() : base("LanguageEntity", TuanHuy.DAL.EntityType.LanguageEntity) { }

		/// <summary>Creates a new, empty LanguageEntity object.</summary>
		/// <returns>A new, empty LanguageEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new LanguageEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewLanguage
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new LanguageEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new LanguageEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewLanguageUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<LanguageEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty ProductsEntity objects.</summary>
	[Serializable]
	public partial class ProductsEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public ProductsEntityFactory() : base("ProductsEntity", TuanHuy.DAL.EntityType.ProductsEntity) { }

		/// <summary>Creates a new, empty ProductsEntity object.</summary>
		/// <returns>A new, empty ProductsEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new ProductsEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewProducts
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new ProductsEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new ProductsEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewProductsUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<ProductsEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty ProductsLanguageEntity objects.</summary>
	[Serializable]
	public partial class ProductsLanguageEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public ProductsLanguageEntityFactory() : base("ProductsLanguageEntity", TuanHuy.DAL.EntityType.ProductsLanguageEntity) { }

		/// <summary>Creates a new, empty ProductsLanguageEntity object.</summary>
		/// <returns>A new, empty ProductsLanguageEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new ProductsLanguageEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewProductsLanguage
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new ProductsLanguageEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new ProductsLanguageEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewProductsLanguageUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<ProductsLanguageEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty ProjectCatogeryEntity objects.</summary>
	[Serializable]
	public partial class ProjectCatogeryEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public ProjectCatogeryEntityFactory() : base("ProjectCatogeryEntity", TuanHuy.DAL.EntityType.ProjectCatogeryEntity) { }

		/// <summary>Creates a new, empty ProjectCatogeryEntity object.</summary>
		/// <returns>A new, empty ProjectCatogeryEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new ProjectCatogeryEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewProjectCatogery
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new ProjectCatogeryEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new ProjectCatogeryEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewProjectCatogeryUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<ProjectCatogeryEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty ProjectsEntity objects.</summary>
	[Serializable]
	public partial class ProjectsEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public ProjectsEntityFactory() : base("ProjectsEntity", TuanHuy.DAL.EntityType.ProjectsEntity) { }

		/// <summary>Creates a new, empty ProjectsEntity object.</summary>
		/// <returns>A new, empty ProjectsEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new ProjectsEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewProjects
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new ProjectsEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new ProjectsEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewProjectsUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<ProjectsEntity>(this);
		}
		

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty ProjectsLanguageEntity objects.</summary>
	[Serializable]
	public partial class ProjectsLanguageEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public ProjectsLanguageEntityFactory() : base("ProjectsLanguageEntity", TuanHuy.DAL.EntityType.ProjectsLanguageEntity) { }

		/// <summary>Creates a new, empty ProjectsLanguageEntity object.</summary>
		/// <returns>A new, empty ProjectsLanguageEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new ProjectsLanguageEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewProjectsLanguage
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new ProjectsLanguageEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new ProjectsLanguageEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewProjectsLanguageUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			return toReturn;
		}
		
		/// <summary>Creates a new generic EntityCollection(Of T) for the entity to which this factory belongs.</summary>
		/// <returns>ready to use generic EntityCollection(Of T) with this factory set as the factory</returns>
		public override IEntityCollection2 CreateEntityCollection()
		{
			return new EntityCollection<ProjectsLanguageEntity>(this);
		}
		

		#region Included Code

		#endregion
	}

	/// <summary>Factory to create new, empty Entity objects based on the entity type specified. Uses  entity specific factory objects</summary>
	[Serializable]
	public partial class GeneralEntityFactory
	{
		/// <summary>Creates a new, empty Entity object of the type specified</summary>
		/// <param name="entityTypeToCreate">The entity type to create.</param>
		/// <returns>A new, empty Entity object.</returns>
		public static IEntity2 Create(TuanHuy.DAL.EntityType entityTypeToCreate)
		{
			IEntityFactory2 factoryToUse = null;
			switch(entityTypeToCreate)
			{
				case TuanHuy.DAL.EntityType.AspnetApplicationsEntity:
					factoryToUse = new AspnetApplicationsEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.AspnetMembershipEntity:
					factoryToUse = new AspnetMembershipEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.AspnetSchemaVersionsEntity:
					factoryToUse = new AspnetSchemaVersionsEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.AspnetUsersEntity:
					factoryToUse = new AspnetUsersEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.CategoryEntity:
					factoryToUse = new CategoryEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.GalleriesEntity:
					factoryToUse = new GalleriesEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.GalleryCategoryEntity:
					factoryToUse = new GalleryCategoryEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.LanguageEntity:
					factoryToUse = new LanguageEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.ProductsEntity:
					factoryToUse = new ProductsEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.ProductsLanguageEntity:
					factoryToUse = new ProductsLanguageEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.ProjectCatogeryEntity:
					factoryToUse = new ProjectCatogeryEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.ProjectsEntity:
					factoryToUse = new ProjectsEntityFactory();
					break;
				case TuanHuy.DAL.EntityType.ProjectsLanguageEntity:
					factoryToUse = new ProjectsLanguageEntityFactory();
					break;
			}
			IEntity2 toReturn = null;
			if(factoryToUse != null)
			{
				toReturn = factoryToUse.Create();
			}
			return toReturn;
		}		
	}
		
	/// <summary>Class which is used to obtain the entity factory based on the .NET type of the entity. </summary>
	[Serializable]
	public static class EntityFactoryFactory
	{
#if CF
		/// <summary>Gets the factory of the entity with the TuanHuy.DAL.EntityType specified</summary>
		/// <param name="typeOfEntity">The type of entity.</param>
		/// <returns>factory to use or null if not found</returns>
		public static IEntityFactory2 GetFactory(TuanHuy.DAL.EntityType typeOfEntity)
		{
			return GeneralEntityFactory.Create(typeOfEntity).GetEntityFactory();
		}
#else
		private static Dictionary<Type, IEntityFactory2> _factoryPerType = new Dictionary<Type, IEntityFactory2>();

		/// <summary>Initializes the <see cref="EntityFactoryFactory"/> class.</summary>
		static EntityFactoryFactory()
		{
			Array entityTypeValues = Enum.GetValues(typeof(TuanHuy.DAL.EntityType));
			foreach(int entityTypeValue in entityTypeValues)
			{
				IEntity2 dummy = GeneralEntityFactory.Create((TuanHuy.DAL.EntityType)entityTypeValue);
				_factoryPerType.Add(dummy.GetType(), dummy.GetEntityFactory());
			}
		}

		/// <summary>Gets the factory of the entity with the .NET type specified</summary>
		/// <param name="typeOfEntity">The type of entity.</param>
		/// <returns>factory to use or null if not found</returns>
		public static IEntityFactory2 GetFactory(Type typeOfEntity)
		{
			IEntityFactory2 toReturn = null;
			_factoryPerType.TryGetValue(typeOfEntity, out toReturn);
			return toReturn;
		}

		/// <summary>Gets the factory of the entity with the TuanHuy.DAL.EntityType specified</summary>
		/// <param name="typeOfEntity">The type of entity.</param>
		/// <returns>factory to use or null if not found</returns>
		public static IEntityFactory2 GetFactory(TuanHuy.DAL.EntityType typeOfEntity)
		{
			return GetFactory(GeneralEntityFactory.Create(typeOfEntity).GetType());
		}
#endif		
	}
		
	/// <summary>Element creator for creating project elements from somewhere else, like inside Linq providers.</summary>
	public class ElementCreator : ElementCreatorBase, IElementCreator2
	{
		/// <summary>Gets the factory of the Entity type with the TuanHuy.DAL.EntityType value passed in</summary>
		/// <param name="entityTypeValue">The entity type value.</param>
		/// <returns>the entity factory of the entity type or null if not found</returns>
		public IEntityFactory2 GetFactory(int entityTypeValue)
		{
			return (IEntityFactory2)this.GetFactoryImpl(entityTypeValue);
		}
		
		/// <summary>Gets the factory of the Entity type with the .NET type passed in</summary>
		/// <param name="typeOfEntity">The type of entity.</param>
		/// <returns>the entity factory of the entity type or null if not found</returns>
		public IEntityFactory2 GetFactory(Type typeOfEntity)
		{
			return (IEntityFactory2)this.GetFactoryImpl(typeOfEntity);
		}

		/// <summary>Creates a new resultset fields object with the number of field slots reserved as specified</summary>
		/// <param name="numberOfFields">The number of fields.</param>
		/// <returns>ready to use resultsetfields object</returns>
		public IEntityFields2 CreateResultsetFields(int numberOfFields)
		{
			return new ResultsetFields(numberOfFields);
		}

		/// <summary>Creates a new dynamic relation instance</summary>
		/// <param name="leftOperand">The left operand.</param>
		/// <returns>ready to use dynamic relation</returns>
		public override IDynamicRelation CreateDynamicRelation(DerivedTableDefinition leftOperand)
		{
			return new DynamicRelation(leftOperand);
		}

		/// <summary>Creates a new dynamic relation instance</summary>
		/// <param name="leftOperand">The left operand.</param>
		/// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
		/// <param name="rightOperand">The right operand.</param>
		/// <param name="onClause">The on clause for the join.</param>
		/// <returns>ready to use dynamic relation</returns>
		public override IDynamicRelation CreateDynamicRelation(DerivedTableDefinition leftOperand, JoinHint joinType, DerivedTableDefinition rightOperand, IPredicate onClause)
		{
			return new DynamicRelation(leftOperand, joinType, rightOperand, onClause);
		}

		/// <summary>Creates a new dynamic relation instance</summary>
		/// <param name="leftOperand">The left operand.</param>
		/// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
		/// <param name="rightOperandEntityName">Name of the entity, which is used as the right operand.</param>
		/// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
		/// <param name="onClause">The on clause for the join.</param>
		/// <returns>ready to use dynamic relation</returns>
		public override IDynamicRelation CreateDynamicRelation(DerivedTableDefinition leftOperand, JoinHint joinType, string rightOperandEntityName, string aliasRightOperand, IPredicate onClause)
		{
			return new DynamicRelation(leftOperand, joinType, (TuanHuy.DAL.EntityType)Enum.Parse(typeof(TuanHuy.DAL.EntityType), rightOperandEntityName, false), aliasRightOperand, onClause);
		}

		/// <summary>Creates a new dynamic relation instance</summary>
		/// <param name="leftOperandEntityName">Name of the entity which is used as the left operand.</param>
		/// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
		/// <param name="rightOperandEntityName">Name of the entity, which is used as the right operand.</param>
		/// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
		/// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
		/// <param name="onClause">The on clause for the join.</param>
		/// <returns>ready to use dynamic relation</returns>
		public override IDynamicRelation CreateDynamicRelation(string leftOperandEntityName, JoinHint joinType, string rightOperandEntityName, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
		{
			return new DynamicRelation((TuanHuy.DAL.EntityType)Enum.Parse(typeof(TuanHuy.DAL.EntityType), leftOperandEntityName, false), joinType, (TuanHuy.DAL.EntityType)Enum.Parse(typeof(TuanHuy.DAL.EntityType), rightOperandEntityName, false), aliasLeftOperand, aliasRightOperand, onClause);
		}
		
		/// <summary>Obtains the inheritance info provider instance from the singleton </summary>
		/// <returns>The singleton instance of the inheritance info provider</returns>
		public override IInheritanceInfoProvider ObtainInheritanceInfoProviderInstance()
		{
			return InheritanceInfoProviderSingleton.GetInstance();
		}
		
		/// <summary>Implementation of the routine which gets the factory of the Entity type with the TuanHuy.DAL.EntityType value passed in</summary>
		/// <param name="entityTypeValue">The entity type value.</param>
		/// <returns>the entity factory of the entity type or null if not found</returns>
		protected override IEntityFactoryCore GetFactoryImpl(int entityTypeValue)
		{
			return EntityFactoryFactory.GetFactory((TuanHuy.DAL.EntityType)entityTypeValue);
		}
#if !CF		
		/// <summary>Implementation of the routine which gets the factory of the Entity type with the .NET type passed in</summary>
		/// <param name="typeOfEntity">The type of entity.</param>
		/// <returns>the entity factory of the entity type or null if not found</returns>
		protected override IEntityFactoryCore GetFactoryImpl(Type typeOfEntity)
		{
			return EntityFactoryFactory.GetFactory(typeOfEntity);
		}
#endif
	}
}
